<?php 
header("content-type:text/html;charset=utf8");
$pdo = new PDO("mysql:host=127.0.0.1;dbname=07c","root","root");
$sql = "select * from store";
$data = $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);

 ?>
 <!DOCTYPE html>
 <html lang="en">
 <head>
 	<meta charset="UTF-8">
 	<title>Document</title>
 </head>
 <body>
 	<center>
 	<div>倒计时<span id="hour">时</span><span id="min">分</span><span id="sec">秒</span></div>
 		<table>
 			<tr>
 				<td>商品图片</td>
 				<td>商品名称</td>
 				<td>价格</td>
 				<td>操作</td>
 			</tr>
 			<?php foreach ($data as $key => $value): ?>
 				<tr>
	 				<td><img src="//img14.360buyimg.com/n1/s450x450_jfs/t1/1867/31/11716/401006/5bd072f8E6db292ab/f3610e2e816ade0f.jpg" alt="" width="100px" height="100px"></td>
	 				<td><?php echo $value['store_name'] ?></td>
	 				<td><?php echo $value['store_price'] ?></td>
	 				<td><button class="qiang" uid="<?php echo $value['store_id'] ?>">抢购</button></td>
	 			</tr>
 			<?php endforeach ?>
 		</table>
 	</center>
 </body>
 </html>
 <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
 <script>
 $(".qiang").click(function(){
 	var uid = $(this).attr("uid");
 	// alert(uid);
 	$.ajax({
 		url:"secondkill.php",
 		data:{uid:uid},
 		type:"post",
 		dataType:"json",
 		success:function(res){
 			alert(res.msg);
 		}
 	})

 })
window.setInterval(function(){
	$.getJSON('times.php','',function(res){
		$("#hour").html(res.hour+"时");
		$("#min").html(res.min+"分");
		$("#sec").html(res.sec+"秒");
	})
},1000)


 </script>
